package com.ffapp.demo.bean;


import android.text.TextUtils;

import com.alibaba.fastjson.annotation.JSONField;

import java.io.Serializable;
import java.util.ArrayList;

public class BaseListDataListBean implements Serializable {
    private static final long serialVersionUID = 1L;

    private ArrayList<BaseListData> list = new ArrayList<BaseListData>();
    private String title;

    @JSONField(name = "data")
    public ArrayList<BaseListData> getList() {
        return list;
    }

    @JSONField(name = "data")
    public void setList(ArrayList<BaseListData> list) {
        this.list = list;
    }


    @JSONField(serialize = false)
    public  ArrayList<String> getListString(){
        ArrayList<String> listString = new ArrayList<>();
        for(BaseListData data:list){
            listString.add(data.getName());
        }
        return  listString;
    }
    @JSONField(serialize = false)
    public  ArrayList<String> getListStringNameID(){
        ArrayList<String> listString = new ArrayList<>();
        for(BaseListData data:list){
            listString.add(data.getName() +"_"+data.getId());
        }
        return  listString;
    }

    @JSONField(serialize = false)
    public  String[] getListStringGroup(){
        if(list == null || list.size() == 0)return null;
        String[] listString = new String[list.size()];
        int i = 0;
        for(BaseListData data:list){
            listString[i] = data.getName();
            i++;
        }
        return  listString;
    }

    @JSONField(serialize = false)
    public BaseListData getDataById(String id){
        if(TextUtils.isEmpty(id))return null;
        for(BaseListData data:list){
           if(id.equals(data.getId()))return data;
        }
        return null;
    }

    @JSONField(serialize = false)
    public String getTitle() {
        return title;
    }

    @JSONField(serialize = false)
    public void setTitle(String title) {
        this.title = title;
    }

    @JSONField(serialize = false)
    public void setCheck(int position){
        list.get(position).setCheck(!list.get(position).isCheck());
    }

    @JSONField(serialize = false)
    public  int getCheckedPosition(BaseListData checkedData){
        if(checkedData == null){
            return -1;
        }
        int i = 0;
        for(BaseListData data:list){
           if(data.getId().equals(checkedData.getId())){
               return i;
           }
           i++;
        }
        return  -1;
    }

    @JSONField(serialize = false)
    public boolean isDataSeletedById(String id){
        if(TextUtils.isEmpty(id))return false;
        for(BaseListData data:list){
            if(id.equals(data.getId()))return data.isCheck();
        }
        return false;
    }
}
